/*
 * 
 * Created on Jul 15, 2005
 */
package com.wgo.precise.client.ui.model;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wgo.precise.client.ui.controller.exceptions.RematoClientException;
import com.wgo.precise.common.VO.Persistent;


/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: Configuration.java,v 1.1 2006-01-23 19:58:37 petterei Exp $
 */
public class Configuration {

	/**
	 * Should use negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)ids
	 */
	private Long baseDefinitionId = null;
	/**
	 * Should use negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)ids
	 */
	private Long categoryDefinitionId = null;
	/**
	 * Should use negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)ids
	 */
	private Long stakeholderDefinitionId = null;
	/**
	 * Should use negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)ids
	 */
	private Long propertyDefSetDefinitionId = null;
	/**
	 * Should use negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)ids
	 */
	private Long propertyDefinitionDefinitionId = null;
	/**
	 * Should use negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)ids
	 */
	private Long requirementDefinitionId = null;
	
	private int baseDefinitionPosition;
	private int categoryDefinitionPosition;
	private int stakeholderDefinitionPosition;
	private int propertyDefSetDefinitionPosition;
	private int propertyDefinitionDefinitionPosition;
	private int requirementDefinitionPosition;
	
//	public static final Long BASE_DEFINITION_ID_START = new Long(0);
//	public static final Long CATEGORY_DEFINITION_ID_START = new Long(-10);
//	public static final Long REQUIREMENT_DEFINITION_ID_START = new Long(-20);
//	public static final Long STAKEHOLDER_DEFINITION_ID_START = new Long(-40);
//	public static final Long PROPERTY_DEFINITION_SET_ID_START = new Long(-50);
	
	public static final int PROJECT_SORT_ORDER = 1;
	public static final int CATEGORY_SORT_ORDER = 2;
	public static final int REQUIREMENT_SORT_ORDER = 3;
	public static final int STAKEHOLDER_SORT_ORDER = 4;
	public static final int PROPERTY_DEFINITION_SET_SORT_ORDER = 5;
	
    private Map<Long,ClientPropertyDefinition<Persistent>> nodeSpesifications = new HashMap<Long,ClientPropertyDefinition<Persistent>>();
    private List<ClientPropertyDefinition<Persistent>> sortedNodeSpesifications = new ArrayList<ClientPropertyDefinition<Persistent>>();

    /**
     * Default value-spesification for .toString()-calls
     */
    private ClientPropertyDefinition<Persistent> nodeTitleSpesification;
    /**
     * Default value-spesification for tool-tip-text
     */
    private ClientPropertyDefinition<Persistent> nodeDescriptionSpecification;
    
    private static Configuration instance;

    /**
     * This class has a constructor, to arrange for possible future server-based configuration.
     * 
     * @param baseDefinitionId Should be negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)IDs
     * @param categoryDefinitionId Should be negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)IDs
     * @param stakeholderDefinitionId Should be negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)IDs
     * @param propertyDefSetDefinitionId Should be negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)IDs
     * @param requirementDefinitionId Should be negative numbers to not interfere with the domain property definition's (<code>PropertyDef</code>)IDs
     */
    public Configuration(Long baseDefinitionId, Long categoryDefinitionId, Long stakeholderDefinitionId, Long propertyDefSetDefinitionId, Long propertyDefinitionDefinitionId, Long requirementDefinitionId) {
		this.baseDefinitionId = baseDefinitionId;
		this.categoryDefinitionId = categoryDefinitionId;
		this.stakeholderDefinitionId = stakeholderDefinitionId;
		this.propertyDefSetDefinitionId = propertyDefSetDefinitionId;
		this.propertyDefinitionDefinitionId = propertyDefinitionDefinitionId; 
		this.requirementDefinitionId = requirementDefinitionId;
		this.baseDefinitionPosition = baseDefinitionId.intValue() * -1;
		this.categoryDefinitionPosition = categoryDefinitionId.intValue() * -1;
		this.stakeholderDefinitionPosition = stakeholderDefinitionId.intValue() * -1;
		this.propertyDefSetDefinitionPosition = propertyDefSetDefinitionId.intValue() * -1;
		this.propertyDefinitionDefinitionPosition = propertyDefinitionDefinitionId.intValue() * -1;
		this.requirementDefinitionPosition = requirementDefinitionId.intValue() * -1;
	}
	public static Configuration getInstance() {
    	if (instance == null ) {
    		instance = new Configuration(new Long(0), new Long(-10), new Long(-20), new Long(-30), new Long(-30), new Long(-40));
    	}
    	return instance;
    }
    public int getIntValue(String variableName){
    	int value;
    	try {
    		Field field = getClass().getDeclaredField(variableName);
			value = field.getInt(this);
		} catch (Exception e) {
    		throw new RematoClientException(e);
		}
    	return value;
    }
    public Long getLongValue(String variableName){
    	Long value = null;
    	try {
    		Field field = getClass().getDeclaredField(variableName);
			long boxedValue = field.getLong(this);
			if (0 != boxedValue) {
				value = new Long(boxedValue);
			}
		} catch (Exception e) {
    		throw new RematoClientException(e);
		}
    	return value;
    }
    public Map<Long,ClientPropertyDefinition<Persistent>> getNodeSpesifications() {
        return nodeSpesifications;
    }

    public List<ClientPropertyDefinition<Persistent>> getSortedNodeSpesifications() {
        return sortedNodeSpesifications;
    }


    public ClientPropertyDefinition<Persistent> getNodeTitleSpesification() {
        return nodeTitleSpesification;
    }

    public synchronized void addNodeSpesification (ClientPropertyDefinition<Persistent> propertySpesification) {
        nodeSpesifications.put(propertySpesification.getIdentifier(), propertySpesification);
        sortedNodeSpesifications.add(propertySpesification);
    }
    
    public void setNodeTitleSpesification(ClientPropertyDefinition<Persistent> nodeTitleSpesification) {
        this.nodeTitleSpesification = nodeTitleSpesification;
    }

	public ClientPropertyDefinition<Persistent> getNodeDescriptionSpecification() {
		return nodeDescriptionSpecification;
	}

	public void setNodeDescriptionSpecification(ClientPropertyDefinition<Persistent> nodeDescriptionSpecification) {
		this.nodeDescriptionSpecification = nodeDescriptionSpecification;
	}
	/**
	 * @return Returns the baseDefinitionId.
	 */
	@SuppressWarnings("boxing")
	public synchronized Long getNextBaseDefinitionId() {
		return baseDefinitionId--;
	}
	/**
	 * @return Returns the baseDefinitionPosition.
	 */
	public synchronized int getNextBaseDefinitionPosition() {
		return baseDefinitionPosition++;
	}
	/**
	 * @return Returns the categoryDefinitionId.
	 */
	@SuppressWarnings("boxing")
	public synchronized Long getNextCategoryDefinitionId() {
		return categoryDefinitionId--;
	}
	/**
	 * @return Returns the categoryDefinitionPosition.
	 */
	public synchronized int getNextCategoryDefinitionPosition() {
		return categoryDefinitionPosition++;
	}
	/**
	 * @return Returns the propertyDefSetDefinitionId.
	 */
	@SuppressWarnings("boxing")
	public synchronized Long getNextPropertyDefSetDefinitionId() {
		return propertyDefSetDefinitionId--;
	}
	/**
	 * @return Returns the propertyDefSetDefinitionPosition.
	 */
	public synchronized int getNextPropertyDefSetDefinitionPosition() {
		return propertyDefSetDefinitionPosition++;
	}
	/**
	 * @return Returns the requirementDefinitionId.
	 */
	@SuppressWarnings("boxing")
	public synchronized Long getNextRequirementDefinitionId() {
		return requirementDefinitionId--;
	}
	/**
	 * @return Returns the requirementDefinitionPosition.
	 */
	public synchronized int getNextRequirementDefinitionPosition() {
		return requirementDefinitionPosition++;
	}
	/**
	 * @return Returns the stakeholderDefinitionId.
	 */
	@SuppressWarnings("boxing")
	public synchronized Long getNextStakeholderDefinitionId() {
		return stakeholderDefinitionId--;
	}
	/**
	 * @return Returns the stakeholderDefinitionPosition.
	 */
	public synchronized int getNextStakeholderDefinitionPosition() {
		return stakeholderDefinitionPosition++;
	}
	/**
	 * @return Returns the propertyDefinitionDefinitionId.
	 */
	@SuppressWarnings("boxing")
	public synchronized Long getNextPropertyDefDefinitionId() {
		return propertyDefinitionDefinitionId--;
	}
	/**
	 * @return Returns the propertyDefinitionDefinitionPosition.
	 */
	public synchronized int getNextPropertyDefDefinitionPosition() {
		return propertyDefinitionDefinitionPosition++;
	}
	
}
/**
 * 
 * Changelog:
 * 
 * $Log: Configuration.java,v $
 * Revision 1.1  2006-01-23 19:58:37  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.7  2006-01-13 08:12:42  petterei
 * Using Long consequently to differentiate between �null� and �0� for dbId and conceptId (no boxing/unboxing)
 * Ajusted code to stronger java-syntax
 *
 * Revision 1.6  2005-12-05 04:16:40  petterei
 * *** empty log message ***
 *
 * Revision 1.5  2005-11-28 21:45:10  petterei
 * refactored most of the client model to wrap the domain-model
 * added some functionality for new domain-model-concepts
 *
 * Revision 1.4  2005/10/24 16:25:36  petterei
 * *** empty log message ***
 *
 * Revision 1.3  2005/10/02 21:31:16  petterei
 * client with new domain model
 *
 * Revision 1.2  2005/09/29 21:20:04  petterei
 * started connecting new model to client
 *
 * Revision 1.1  2005/09/27 17:04:29  petterei
 * inittial commit
 *
 * Revision 1.3  2005/08/26 15:11:44  peide3
 * fixed bug in properties view (using propertyspecification as id, instead of object)
 *
 * Revision 1.2  2005/08/25 09:46:30  peide3
 * added batch update + bugfixes
 *
 * Revision 1.1  2005/08/23 06:38:48  peide3
 * *** empty log message ***
 *
 * Revision 1.1  2005/07/31 22:55:09  petterei
 * initial commit
 *
 * Revision 1.3  2005/07/20 13:58:56  peide3
 * *** empty log message ***
 *
 */
